
#pragma once

#include <ecal/ecal_payload_writer.h>

#include <cstring>

// a binary payload
class CBinaryPayload : public eCAL::CPayloadWriter {
 public:
  CBinaryPayload(size_t size_) : size(size_) {}

  bool WriteFull(void* buf_, size_t len_) override {
    // write complete content to the shared memory file
    if (len_ < size) return false;
    memset(buf_, 42, size);
    return true;
  };

  bool WriteModified(void* buf_, size_t len_) override {
    // update content of the shared memory file
    if (len_ < size) return false;
    const size_t write_idx((clock % 1024) % len_);
    const char write_chr(clock % 10 + 48);
    static_cast<char*>(buf_)[write_idx] = write_chr;
    clock++;
    return true;
  };

  size_t GetSize() override { return size; };

 private:
  size_t size = 0;
  int clock = 0;
};
